<?php
/*
	[English learning system]
	NAME:admin_control
*/
if (!defined('IN_ELS'))
{
    die('Hacking attempt');
}
class control extends userbase {
	var $pagecount 		= 0;
	var $currendnum 	= 1;
	var $pageSize 		= 15;	//每页多少条
	var $pageNumSize 	= 10;	//分页数
	
	function control() {
		$this->userbase();
		if(!empty($_REQUEST['currendnum'])){
			$this->currendnum=$_REQUEST['currendnum'];
		}
		$act=empty($_REQUEST['a']) ? 'empty' : $_REQUEST['a'];
		//会员类表
		if($act=="empty") 				$this->userList();
		if($act=="information") 		$this->information();
		if($act=="userupdate") 			$this->userupdate();
		if($act=="delProducts") 		$this->delProducts();
		if($act=="delall") 				$this->delall();
		if($act=="switch") 				$this->switchlist();
		if($act=="switchSave") 			$this->switchSave();
		if($act=="editor")				$this->editorList();
		if($act=="adminsetting")		$this->adminSetting();
	}  
	function userList(){
		$class=	$_REQUEST['class'];
		$title=	$_REQUEST['title'];
		$type=	$_REQUEST['type'];
		$where = " where 1=1 ";
		$url = "";
		if(!empty($title)){
			if($class=="1"){
			$where .=" and nickname like '%$title%' ";
			}
			if($class=="2"){
			$where .=" and mobile_phone like '%$title%' ";
			}
			if($class=="3"){
			$where .=" and address like '%$title%' ";
			}
		}
		if($type=="1"){
		$where .=" and type='1' ";
		}
		if($type=="2"){
		$where .=" and type='2' ";
		}
//		echo $where;exit;
		if(!empty($_REQUEST['currendnum'])){
			$this->currendnum=$_REQUEST['currendnum'];
		}
		$memberCount=$this->getMemberCount();
		$shangjiaCount=$this->getMembershangjiaCount();
		$dataCount=$this->getdataCount($where);
		$startNum = $this->pageSize*($this->currendnum-1);
		$limitText = " limit ".$startNum." , ".$this->pageSize;
		$pagecountdata=array();
		require_once ELS_ROOT.'lib/paging.class.php';
		$pg =  new paging();
		$pg -> setLinkText("<a href='?p=user&currendnum=!!PageNum!!'>!!LinkText!!</a>");
		$pg -> setCurrendnum(  $this-> currendnum);
		$pg -> setPageSize(    $this-> pageSize);
		$pg -> setPageNumSize( $this-> pageNumSize);
		$pg -> setDataCount(   $dataCount);
		$pagecountdata = $pg ->makePageText();
		
		$value = $this->getdataList($where,$limitText);
		//摘要截取
		$summarylen = 26;
		for($i=0;$i<count($value);$i++){
			$value[$i]['title_str'] = $this->getstr($value[$i]['title'], $summarylen, 0, 0, 0, 0, -1);
			$list[] = $value[$i];
		}
		$this->view->assign('list',$list);
		$this->view->assign('pagecount' ,$pagecountdata);
		$this->view->assign('class',$class);
		$this->view->assign('type',$type);
		$this->view->assign('memberCount',$memberCount);
		$this->view->assign('shangjiaCount',$shangjiaCount);
		$this->view->assign('currendnum',$currendnum);
		$this->view->assign('active_type' ,$active_type);
		$this->view->display("admin_user_list");
	}
	function information(){
		$mid = empty($_REQUEST['mid'])?0:intval($_REQUEST['mid']);
		$data=$this->getinformation($mid);
		$this->view->assign('data' ,$data);
		$this->view->display("admin_uesr_information");
	}
	function userupdate(){
		$mid = empty($_REQUEST['mid'])?0:intval($_REQUEST['mid']);
		$nickname		 =	$_REQUEST['nickname'];
		$password		 =	$_REQUEST['password'];
		$address		 =	$_REQUEST['address'];
		$mobile_phone	 =	$_REQUEST['mobile_phone'];
		$type			 =	$_REQUEST['type'];
		$sex			 =	$_REQUEST['sex'];
		$email			 =	$_REQUEST['email'];
		$name			 =	$_REQUEST['name'];
		$user_type		 =	$_REQUEST['user_type'];
		
		$upsucc = true;
		$dataArray = array();
		
	//	if($name==""){
	//		$this->view->assign('name_err'  ,"真实姓名不能为空");
	//		$hasError = true;
	//	}
		if($address==""){
			$this->view->assign('address_err'  ,"所在地区不能为空");
			$hasError = true;
		}
		if(empty($mobile_phone)){
			$this->view->assign('mobile_phone_err'  ,"手机号码不能为空");
			$hasError = true;
		}elseif (!eregi("^13[0-9]{9}$|15[0-9]{9}$|18[0-9]{9}$",$mobile_phone)) {
			$this->view->assign('mobile_phone_err'  ,"该手机号码格式不正确");
			$hasError = true;
		}elseif(!empty($mobile_phone)){
			$mobile_phones=$this->getinformation_phone($mobile_phone,$mid,$type);
			if($mobile_phone==$mobile_phones['mobile_phone']){
				$this->view->assign('mobile_phones_err'  ,"手机号码已存在");
				$hasError = true;
			}
		}
		if($type==""){
			$this->view->assign('type_err'  ,"验证状态不能为空");
			$hasError = true;
		}
		if($password){
			$dataArray['password'] 		= md5($password);
		}
		
		//if($email==""){
		//	$this->view->assign('email_err'  ,"电子邮箱不能为空");
		//	$hasError = true;
		//}
		
		$this->view->assign('data' ,$data);
		
		$dataArray['nickname'] 		= $nickname;
		$dataArray['mobile_phone'] 	= $mobile_phone;
		$dataArray['address'] 		= $address;
		$dataArray['type'] 			= $type;
		$dataArray['name'] 			= $name;
		$dataArray['email'] 		= $email;
		$dataArray['sex'] 			= $sex;
		$dataArray['user_type'] 	= $user_type;
		if($hasError){
			$mid = empty($_REQUEST['mid'])?0:intval($_REQUEST['mid']);
			$data=$this->getinformation($mid);
			$this->view->assign('data' ,$data);
			$this->view->display("admin_uesr_information");
			exit;
		}
		$where = " mid='$mid'";
		$this->getuser_Update($dataArray,$where);
		
		$this->pageRedirect("?p=user");
	}
	function delProducts(){
		$mid = empty($_REQUEST['mid'])?0:intval($_REQUEST['mid']);
		$this->db->query("DELETE FROM members WHERE mid = '$mid'");
		$this->pageRedirect("?p=user");
	}
	function delall(){
		$mids = empty($_POST['ids'])?array():$_POST['ids'];
		//删除
		if($mids){
			for($i=0;$i<count($mids);$i++){
				$this->db->query("DELETE FROM members WHERE mid = '$mids[$i]'");
			}
		}
		$this->pageRedirect("?p=user");
	}
	function switchlist(){
		$data=$this->getswitchlist();
	
		$this->view->assign('data' ,$data);
		
		$this->view->display("admin_switch");
	}
	function switchSave(){
		$shangwang		 =	$_REQUEST['shangwang'];
		$youhuiquan		 =	$_REQUEST['youhuiquan'];
		$title3			 =	$_REQUEST['title3'];
		$title2			 =	$_REQUEST['title2'];
		$title1		  	 =	$_REQUEST['title1'];
		$huodong		 =	$_REQUEST['huodong'];
		$dataArray = array();
		
		if($title1){
			$dataArray['title1']	= $title1;
		}
		if($title2){
			$dataArray['title2']	= $title2;
		}
		if($title3){
			$dataArray['title3']	= $title3;
		}
		if($shangwang){
			$dataArray['shangwang']	= $shangwang;
			$dataArray['updata_time']	= $this->getCurrTimeLine();
		}
		if($youhuiquan){
			$dataArray['youhuiquan']	= $youhuiquan;
			$dataArray['updata_time']	= $this->getCurrTimeLine();
		}
		if($huodong){
			$dataArray['huodong']		= $huodong;
			$dataArray['updata_time']	= $this->getCurrTimeLine();
		}
		
		
		$where = "id='1'";
		
 		$this->updateswitch($dataArray,$where);
 		
		$this->pageRedirect("?p=user&a=switch");
	}
	function editorList(){
		$this->view->assign('setting',$setting);
		$this->view->display("admin_switch");
	}

}
?>